<template>
  <div>
    <el-form ref="form" :model="SystemData" label-width="80px">
      <div>
        服务器名称：<el-input
          :disabled="isCompile"
          v-model="SystemData.serviceName"
          style="width: 70% !important"
        ></el-input>
      </div>
      <br />
      <div>
        <span
          >数据库链接地址：<el-input
          :disabled="isCompile"
            v-model="SystemData.connectionString.default"
            class="size"
          ></el-input
        ></span>
        <span>
          Redis链接地址：<el-input
          :disabled="isCompile"
            v-model="SystemData.connectionString.redis"
            class="size"
          ></el-input
        ></span>
      </div>
      <br />
      <div>
        <span
          >限流多少秒：<el-input
          :disabled="isCompile"
            v-model="SystemData.currentLimiting.count"
            style="width: 30% !important"
          ></el-input
        ></span>
        <span>
          限流多少秒限制多少次：<el-input
          :disabled="isCompile"
            v-model="SystemData.currentLimiting.second"
            style="width: 30% !important"
          ></el-input
        ></span>
      </div>
      <div>
        <span
          >服务器上传最大限制（MB）：<el-input
          :disabled="isCompile"
            v-model="SystemData.fileServer.singleFileMaxSize"
            style="width: 30% !important"
          ></el-input
        ></span>
        <span>
          系统信息推送间隔（秒）：<el-input
          :disabled="isCompile"
            v-model="SystemData.pushTime"
            style="width: 30% !important"
          ></el-input
        ></span>
      </div>
      <br/>
      <div>
        阿里云Oss设置<br/>
        <div>
        <span
          >endpoint：<el-input
          :disabled="isCompile"
            v-model="SystemData.oss.endpoint"
            style="width: 12% !important"
          ></el-input
        ></span>
        <span>
          accessKeyId：<el-input
          :disabled="isCompile"
            v-model="SystemData.oss.accessKeyId"
            style="width: 12% !important"
          ></el-input
        ></span>
        <span>
          accessKeySecret：<el-input
          :disabled="isCompile"
            v-model="SystemData.oss.accessKeySecret"
            style="width: 12% !important"
          ></el-input
        ></span>
        <span>
          bucketName：<el-input
          :disabled="isCompile"
            v-model="SystemData.oss.bucketName"
            style="width: 12% !important"
          ></el-input
        ></span>
        <span>
          下载前缀路径：<el-input
          :disabled="isCompile"
            v-model="SystemData.oss.path"
            style="width: 12% !important"
          ></el-input
        ></span>
      </div>
      </div>
      <br />
      <el-form-item>
        <el-button type="primary" @click="()=>{isCompile=!isCompile}">{{isCompile?"编辑":"取消编辑"}}</el-button>
        <el-button 
          :disabled="isCompile" @click="SetSystemSettings">更改</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import { GetSystemSettings,SetSystemSettings} from "../config/SystemSettings";
import { get,put} from "../util/request";
export default {
  data() {
    return {
      isCompile:true,
      SystemData: {
        connectionString: {
          default: "",
          redis: "",
          mongoDB: "",
          mongoDBData: "",
        },
        serviceName: "",
        currentLimiting: {
          second: 0,
          count: 0,
        },
        fileServer: {
          singleFileMaxSize: 0,
        },
        oss: {
          endpoint: "",
          accessKeyId: "",
          accessKeySecret: "",
          bucketName: "",
          path: "",
        },
        pushTime: 0,
      },
    };
  },
  methods: {
    SetSystemSettings(){
      put(SetSystemSettings,this.SystemData)
        .then(response=>{
          if(response.statusCode===200){
            this.$message.success("编辑成功")
          }
        })
        
    },
    GetSystemSettings() {
      get(GetSystemSettings).then((response) => {
        if (response.statusCode === 200) {
          this.SystemData = response.value;
        }
      });
    },
  },
  created() {
    this.GetSystemSettings();
  },
};
</script>
<style>
.size {
  width: 18% !important;
}
</style>